package main

import (
	"fmt"
	"log"
	"reflect"
	"strconv"
	"unicode/utf8"
)

const (
	ser = iota
	s
	dd
	cc
)

var sdmap = map[int]string{
	ser: "asd",
	s:   "dde",
	dd:  "kso",
}

func functest1main() {
	fmt.Println(Sum("22", "2"))
	ss := Sum
	dd := LogMiddleware(ss)
	dd = logMiddleware2(ss)
	fmt.Println(dd("1", "2"))
	cc := 99
	zeroptr(&cc)
}
func Sum(a, b string) (sum int, err error) {
	parseInta, err := strconv.Atoi(a)
	if err != nil {
		return 0, err
	}
	parseIntb, err := strconv.ParseInt(b, 10, 0)
	if err != nil {
		return 0, err
	}
	sum = int(int64(parseInta) + parseIntb)
	return
}

type sumstutrs func(a, b string) (sum int, err error)

func LogMiddleware(ii sumstutrs) sumstutrs {
	return func(a, b string) (sum int, err error) {
		log.Printf("a : %s  ,   b:%s  :", a, b)
		return ii(a, b)
	}
}
func logMiddleware2(ii func(a, b string) (sum int, err error)) func(a, b string) (sum int, err error) {
	return func(a, b string) (sum int, err error) {
		log.Printf("a : %s  ,   b:%s  :", a, b)
		return ii(a, b)
	}
}

func zeroptr(ips *int) {
	fmt.Println(ips)
	fmt.Println(reflect.ValueOf(ips).Elem())
	const s = "สวัสดี"
	for idx, runeValue := range s {
		fmt.Printf("%#U starts at %d\n", runeValue, idx)
	}
	for i, w := 0, 0; i < len(s); i += w {
		runeValue, width := utf8.DecodeRuneInString(s[i:])
		fmt.Printf("%#U starts at %d\n", runeValue, i)
		w = width
	}
	fmt.Println(person{"222", 3})
	fmt.Println(reflect.TypeOf(&person{name: "Ann", age: 40}))

	dog := struct {
		name string
		age  int
	}{
		name: "kso",
		age:  30,
	}
	fmt.Println(dog)

}

type geointer interface {
	area() int
	perim() string
}
type person struct {
	name string
	age  int
}

type geoperson struct {
	name string
}

func (g geoperson) area() int {
	return len(g.name)
}
func (g geoperson) perim() string {
	return g.name
}
func (p person) area() int {
	return p.age
}

type sint int

func transition(s sint, dd sint, g geoperson) sint {
	switch s {
	case ser:
		return ser
	case dd:
		return dd
	default:
		return dd
	}
}
